var ROOT = '';
var SERVLET_ROOT = '';
var IMAGES = 'images';
var INCLUDE = 'include';

DELIM_ROW = '\1';
DELIM_COL = '\2';

ACTN_LOGIN = 1;
ACTN_LOGOUT = 2;
ACTN_OPEN = 3;
ACTN_SAVE = 4;
ACTN_SEARCH = 5;
ACTN_SCROLL_TO_PAGE = 6;
ACTN_NEW_RECORD = 7;
ACTN_EDIT_RECORD = 8;
ACTN_VIEW_RECORD = 9;
ACTN_COPY_RECORD = 10;
ACTN_DELETE_RECORD = 11;
ACTN_CANCEL = 12;
ACTN_GET_SLOT = 13;
ACTN_SHOW_TAB = 14;
ACTN_OPEN_FOR_SELECT = 15;
ACTN_SELECT = 16;
ACTN_VALIDATE_FIELD = 17;
ACTN_SORT_BY_COLUMN = 18;
ACTN_BUTTON_CLICKED = 19;
ACTN_TOGGLE_BOOKMARK_FILTER = 20;
ACTN_SUBMIT = 21;
ACTN_TOGGLE_BOOKMARK = 22;
ACTN_ZOOM_IN = 23;
ACTN_ZOOM_LEVEL = 24;
ACTN_SCROLL_TO_ROW = 25;
ACTN_RESET = 26;
ACTN_SELECT_ROW = 27;
ACTN_CANCEL_SUB_PAGE = 28;
ACTN_ITEM_CLICKED = 29;
ACTN_REFRESH = 30;
ACTN_SHOW_DESK
        = 31;
ACTN_SHOW_PAGE_ACTIONS = 32;
ACTN_PERFORM_PAGE_ACTION = 33;
ACTN_SHOW_ITEM_DETAIL = 34;
ACTN_SET_SCREEN_MODE = 35;
ACTN_SHOW_SECTION_TAB = 36;
ACTN_LOGIN_OR_JOIN = 37;
ACTN_MENU_ITEM_CLICKED = 38;
ACTN_RESET_DESKTOP = 39;

MODE_POPUP = 1;

miSelectedRow = 0;
miAvailableSelectedRow = 0;

function showJSError(fsMSG, fsURL, fiLineNumber)
{
	window.status = fsMSG + " at line: " + fiLineNumber;
	return true
}
//window.onerror=showJSError

function getDataFrame()
{
	return self;
}

function getDataDocument()
{
	return getDataFrame().document;
}

function getDataForm()
{
   return getDataDocument().DataForm;
}

function getPopupFrame()
{
   return getDataDocument().getElementById("PopupFrame");
}

function getPopupDocument()
{
	if (self.name == "PopupFrame") return document;

   loWindow = getDataFrame();
   for(var i=0; i<loWindow.frames.length; i++)
   {
      if (loWindow.frames[i].name == "PopupFrame")
      {
         return loWindow.frames[i].document;
      }
   }
}

function getPopupForm()
{
   return getPopupDocument().PopupForm;
}

function checkForFrame()
{
   loForm = getDataForm();
	if (!loForm.frame_no && parent == top.DataFrame)
	{
		loForm = getDataForm();
		loForm.setAttribute("action", top.SERVLET_ROOT + "Controller");
		loForm.setAttribute("method", "post");
		loForm.action_fld.value = ACTN_REFRESH;
		loForm.target = "_parent";
		loForm.submit();
	}
}

function showDesktop()
{
	processRequest(ACTN_SHOW_DESKTOP);
}

function setMainMenu(foMenuBar)
{
	setMenuBar(foMenuBar, "MainMenu");
}

function setPageActionMenu(foMenuBar)
{
	setMenuBar(foMenuBar, "PageActionMenu");
}

function setMenuBar(foMenuBar, fsMenuDiv)
{
	var loHeaderDocument = top.HeaderFrame.document;
	var loMenuDiv = loHeaderDocument.getElementById(fsMenuDiv);
	foMenuBar._document = loHeaderDocument;
	var lsHTML = foMenuBar.toHtml();
	loMenuDiv.innerHTML = lsHTML;
	var loMenuBarElement = loHeaderDocument.getElementById(foMenuBar.id);
	foMenuBar.hookupMenu(loMenuBarElement);
}

function loadPageActions()
{
	loPageActionElement = top.HeaderFrame.document.getElementById('page_action');
	miPageActionMenuX = window.screenLeft + getOffsetLeft(loPageActionElement);
	miPageActionMenuY = window.screenTop + getOffsetTop(loPageActionElement) + loPageActionElement.clientHeight + 2;

	//miPageActionMenuX = event.screenX - event.offsetX - 46;
   //miPageActionMenuY = event.screenY - event.offsetY + 19;

	loPageActionMenu = new Menu();
	loPageActionMenu.add(new MenuItem('Loading ...'));
	loPageActionMenu.show(miPageActionMenuX, miPageActionMenuY);

	preparePopupForm();
	processRequestPopup(ACTN_SHOW_PAGE_ACTIONS);
}

function NodeItem()
{
	this.maChildren = null;
	this.msName = null;
	this.msValue = null;
	this.msAction = null;
}

function showPageActions(foRootNode)
{
	loPageActionElement = top.HeaderFrame.document.getElementById('page_action');
	miPageActionMenuX = window.screenLeft + getOffsetLeft(loPageActionElement);
	miPageActionMenuY = window.screenTop + getOffsetTop(loPageActionElement) + loPageActionElement.clientHeight + 2;

	loPageActionMenu = new Menu();

	var laChildren = foRootNode.maChildren;
   for(i=0; i < laChildren.length; i++)
   {
		processPageActionNode(laChildren[i], loPageActionMenu);
   }

	loPageActionMenu.show(miPageActionMenuX, miPageActionMenuY);
}

function processPageActionNode(foNode, foParentMenu)
{
	var laChildren = foNode.maChildren;
	if (laChildren != null)
	{
		loSubMenu = new Menu();
		loMenuItem  = new MenuItem(foNode.msName, null, null, loSubMenu);
		foParentMenu.add(loMenuItem);
		for(j=0; j < laChildren.length; j++)
		{
			processPageActionNode(laChildren[j], loSubMenu);
		}
	}
	else
	{
		loMenuItem = new MenuItem(foNode.msName, "javascript:performPageAction(" + foNode.msAction + ")");
		foParentMenu.add(loMenuItem);
	}
}

function performPageAction(fiPageAction)
{
	processRequest(ACTN_PERFORM_PAGE_ACTION, fiPageAction);
}

function openPage(fsPageName)
{
    if (arguments.length == 1)
   {
		processRequest(ACTN_OPEN, fsPageName);
	}
	else
	{
		processRequest(ACTN_OPEN, fsPageName, arguments[1]);
	}
}

function openForSelect(fsFieldName)
{
	processRequest(ACTN_OPEN_FOR_SELECT, fsFieldName);
}

function openForSelectPopup(fsFieldName, fbScrolling)
{
	setPopupScrolling(fbScrolling);
	preparePopupForm();
	if (arguments.length > 2) 	liPopupWidth = arguments[2] * 8 ; else liPopupWidth = 312;
	if (liPopupWidth == 0) liPopupWidth = 312;
   showPopup(fsFieldName, liPopupWidth);
	processRequestPopup(ACTN_OPEN_FOR_SELECT, fsFieldName);
}

function setPopupScrolling(fbScrolling)
{
   loPopupFrame = getPopupFrame();
	if (fbScrolling)
	{
		lsScrolling = "auto";
	}
	else
	{
      lsScrolling = "no";
	}

	if (loPopupFrame.scrolling != lsScrolling)
	{
		loPopupFrame.scrolling = lsScrolling;
		loPopupFrame.outerHTML = loPopupFrame.outerHTML;
	}
}

function performSearch()
{
	processRequest(ACTN_SEARCH, "N");
}

function performRefresh()
{
	processRequest(ACTN_REFRESH);
}

function setScreenMode(fiScreenMode)
{
	processRequest(ACTN_SET_SCREEN_MODE, fiScreenMode);
}

function bookmarkSearch()
{
	processRequest(ACTN_SEARCH, "Y");
}

function scrollToPage(fiPage)
{
	processRequest(ACTN_SCROLL_TO_PAGE, fiPage);
}

function showTab(fiTab)
{
	processRequest(ACTN_SHOW_TAB, fiTab);
}

function newRecord()
{
   processRequest(ACTN_NEW_RECORD);
}

function viewRecord()
{
   processRequest(ACTN_VIEW_RECORD, miSelectedRow);
}

function editRecord()
{
   liSelectedRow = miSelectedRow;
   if (arguments.length > 0) liSelectedRow = arguments[0];
    processRequest(ACTN_EDIT_RECORD, liSelectedRow);
}

function copyRecord()
{
   processRequest(ACTN_COPY_RECORD, miSelectedRow);
}

function deleteRecord()
{
   lbReply = confirm("Are you sure you want to delete this record?")
   if (lbReply)
   {
      processRequest(ACTN_DELETE_RECORD, miSelectedRow);
   }
}

function markDelete()
{
   processRequest(ACTN_DELETE_RECORD, miSelectedRow);
}

function saveRecord()
{
   processRequest(ACTN_SAVE);
}

function performSelect()
{
   processRequest(ACTN_SELECT, miSelectedRow);
}

function performSelectPopup(fiSelectedRow)
{
   processRequestPopup(ACTN_SELECT, fiSelectedRow);
}

function performCancel()
{
   processRequest(ACTN_CANCEL);
}

function performCancelSubPage()
{
   processRequest(ACTN_CANCEL_SUB_PAGE);
}

function performReset()
{
   processRequest(ACTN_RESET);
}

function getFromSlot(fiSlot)
{
   processRequest(ACTN_GET_SLOT, fiSlot);
}

function performSelectRow(fiRow)
{
   if (miSelectedRow == fiRow) return;
   processRequest(ACTN_SELECT_ROW, fiRow);
}

function selectRow(fiRow)
{
   if (miSelectedRow > 0)
   {
      loRow = document.getElementById("row" + miSelectedRow);
      loRow.className = miSelectedRow % 2 != 0 ? "" : "readOnly";
	   loSelRow = document.getElementById("SelRow" + miSelectedRow);
	   if (loSelRow != null)
	   {
			loSelRow.value="N";
			loSelRow.checked=false;
	  	}
   }

   loRow = document.getElementById("row" + fiRow);
   loRow.className = "selectedItem";
   loSelRow = document.getElementById("SelRow" + fiRow);
   if (loSelRow != null)
   {
		loSelRow.value="Y";
		loSelRow.checked=true;
	}
   miSelectedRow = fiRow;
   setEnabled("copy", true);
   setEnabled("edit", true);
   setEnabled("delete", true);
   setEnabled("select", true);
}
function selectRowFromSelected(fiRow)
{
   if (miSelectedRow > 0)
   {
      loRow = document.getElementById("row" + miSelectedRow);
      loRow.className = miSelectedRow % 2 != 0 ? "" : "readOnly";
   }
   if (miAvailableSelectedRow > 0)
   {
      loRow = document.getElementById("availableRow" + miAvailableSelectedRow);
      loRow.className = miAvailableSelectedRow % 2 != 0 ? "" : "readOnly";
   }

   loRow = document.getElementById("row" + fiRow);
   loRow.className = "selectedItem";
   miSelectedRow = fiRow;
   setEnabled("Unselect", true);
   setEnabled("Select", false);
}

function selectRowFromAvailable(fiRow)
{
   if (miAvailableSelectedRow > 0)
   {
      loRow = document.getElementById("availableRow" + miAvailableSelectedRow);
      loRow.className = miAvailableSelectedRow % 2 != 0 ? "" : "readOnly";
   }
   if (miSelectedRow > 0)
   {
      loRow = document.getElementById("row" + miSelectedRow);
      loRow.className = miSelectedRow % 2 != 0 ? "" : "readOnly";
   }
   loRow = document.getElementById("availableRow" + fiRow);
   loRow.className = "selectedItem";
   miAvailableSelectedRow = fiRow;
   setEnabled("Unselect", false);
   setEnabled("Select", true);
}

function toggleBookmark(fiRow)
{
   selectRow(fiRow);
   processRequest(ACTN_TOGGLE_BOOKMARK, miSelectedRow);
}

function selectDeletedRow(fiRow)
{
   selectRow(fiRow)
   setEnabled("edit", false);
}

function sortByColumn(fiSortColumn)
{
   processRequest(ACTN_SORT_BY_COLUMN, fiSortColumn);
}

function zoomIn(fiLevel, fiRow)
{
   processRequest(ACTN_ZOOM_IN, fiLevel, fiRow);
}

function zoomLevel(fiLevel)
{
   processRequest(ACTN_ZOOM_LEVEL, fiLevel);
}

function buttonClicked(fbName)
{
   if (fbName == "Select")
   {
        processRequest(ACTN_BUTTON_CLICKED, fbName, miAvailableSelectedRow);
    }
    else
    {
        processRequest(ACTN_BUTTON_CLICKED, fbName, miSelectedRow);
    }
}

function menuItemClicked(fiAction)
{
	processRequest(ACTN_MENU_ITEM_CLICKED, fiAction, miSelectedRow);
}

function showItemDetail(fsFieldName, fiRow, fiCol)
{
   processRequest(ACTN_SHOW_ITEM_DETAIL, fiRow, fiCol);
}

function showItemDetailPopup(fsFieldName, fiRow, fiCol)
{
	setPopupScrolling(false);
	preparePopupForm();
   showPopup(fsFieldName, 400);
   processRequestPopup(ACTN_SHOW_ITEM_DETAIL, fiRow, fiCol);
}

function itemClicked(fiRow, fiItemArea)
{
   processRequest(ACTN_ITEM_CLICKED, fiRow, fiItemArea);
}

function itemClickedPopup(fiRow, fiItemArea)
{
   processRequestPopup(ACTN_ITEM_CLICKED, fiRow, fiItemArea);
}

function setEnabled(fsName, fbEnabled)
{
   loButton = document.getElementById(fsName);
   if (loButton)
   {
      loButton.disabled = !fbEnabled;
   }
}

function performSubmit()
{
	processRequest(ACTN_SUBMIT);
}

function logout()
{
   loForm = getDataForm();
   loForm.setAttribute("action", top.SERVLET_ROOT + "Controller");
   loForm.setAttribute("method", "post");
	if (loForm.frame_no) loForm.target = "_parent";
	loForm.action_fld.value = ACTN_LOGOUT;
	loForm.submit();
}

function processRequest(fsAction)
{
    lsAction = fsAction;
   if (arguments.length > 1) lsAction += "^" + arguments[1];
   if (arguments.length > 2) lsAction += "^" + arguments[2];
   if (arguments.length > 3) lsAction += "^" + arguments[3];
   if (arguments.length > 4) lsAction += "^" + arguments[4];
	submitRequest(lsAction);
}

function submitRequest(fsAction)
{
	loDocument = getDataDocument();
	loDocument.body.style.cursor = "wait";
    loForm = getDataForm();
    loForm.setAttribute("action", top.SERVLET_ROOT + "Controller");
    loForm.setAttribute("method", "post");
	loForm.action_fld.value = fsAction;
    loForm.submit();
}
  
function validateField(fsFieldName)
{
	var lsReferenceDataKey = null;
   if (arguments.length > 1) lsReferenceDataKey = arguments[1];

   loMessageDiv = getDataDocument().getElementById("message_div");
   if (loMessageDiv)
   {
   	loMessageDiv.innerHTML = "";
		loMessageDiv.className = "invisible";
   }
   lsFieldValue = document.getElementById(fsFieldName).value;
   loDisplayField = document.getElementById(fsFieldName + "_refvalue");

   if (loDisplayField)
   {
      if (lsFieldValue == null || lsFieldValue == "")
      {
         loDisplayField.value = "";
         return;
      }
   }

   if (lsReferenceDataKey != null && lsReferenceDataKey != "")
   {
   	var lsReferenceData = top.maReferenceData[lsReferenceDataKey];
   	if (lsReferenceData)
   	{
   		validateFieldRefData(fsFieldName, lsReferenceData);
   		return;
	   }
   }

	preparePopupForm();
   showPopup(fsFieldName, 312);
	processRequestPopup(ACTN_VALIDATE_FIELD, fsFieldName, lsReferenceDataKey);
}

function validateFieldRefData(fsFieldName, fsReferenceData)
{
   var loDocument = getDataDocument();
   var loField = loDocument.getElementById(fsFieldName);
   lsValue = loField.value;
   liPos = fsReferenceData.indexOf(DELIM_ROW + lsValue + DELIM_COL);
   if (liPos == -1)
   {
   	loField.focus();
   	displayMessage("Invalid value");
   }
   else
   {
		liStart = liPos + lsValue.length + 2;
		liEnd = fsReferenceData.indexOf(DELIM_ROW, liStart);
		lsDisplayValue = fsReferenceData.substr(liStart, liEnd - liStart);
		loDisplayValue = loDocument.getElementById(fsFieldName + "_refvalue");
		loDisplayValue.value = lsDisplayValue;
		displayMessage("");
   }
}

function storeReferenceData(fsReferenceDataKey, fsReferenceData)
{
	top.maReferenceData[fsReferenceDataKey] = fsReferenceData;
}

function scrollPopup(fiStartRow)
{
	processRequestPopup(ACTN_SCROLL_TO_ROW, fiStartRow);
}

function tooglePopupBookmarkFilter()
{
	processRequestPopup(ACTN_TOGGLE_BOOKMARK_FILTER);
}

function processRequestPopup(fsAction)
{
   lsAction = fsAction;
   if (arguments.length > 1)
   {
	   if (arguments[1] == null) arguments[1] = "";
	   lsAction += "^" + arguments[1];
   }
   if (arguments.length > 2)
   {
   	if (arguments[2] == null) arguments[2] = "";
   	lsAction += "^" + arguments[2];
   }
   if (arguments.length > 3)
   {
   	if (arguments[3] == null) arguments[3] = "";
   	lsAction += "^" + arguments[3];
   }
   if (arguments.length > 4) lsAction += "^" + arguments[4];
	submitRequestPopup(lsAction);
}

function submitRequestPopup(fsAction)
{
   loForm = getPopupForm();
   loForm.setAttribute("action", top.SERVLET_ROOT + "Controller");
   loForm.setAttribute("method", "post");
	loForm.action_fld.value = fsAction;
	loForm.submit();
}

function preparePopupForm()
{
	loPopupFrame = getPopupFrame();
   lsData = "<html>";
   lsData += "<head>";
   lsData += "<link href='" + top.INCLUDE + "/Stylesheet.css' type='text/css' rel='stylesheet'>";
   lsData += "</head>";
   lsData += "<body>";
   lsData += "<table width=100% cellspacing=0 cellpadding=0 class='calborderin'>";
   lsData += "<tr><td style='cursor: wait' align=center>";
   lsData += "Processing ...";
   lsData += "</td></tr></table>";
   lsData += "<form name='PopupForm'>";
   lsData += "<input type='hidden' name='screen_mode' value='" + MODE_POPUP + "'>";

	var loDataDocument = getDataDocument();
   var loDataForm = getDataForm();

   var loFields = getFormFields(loDataForm);
   for (var i=0; i<loFields.length; i++)
   {
		lsData += "<input type='hidden' name='" + loFields[i].name + "'>";
   }

   lsData += "</form>";
   lsData += "</body>";
   lsData += "</html>";

   loPopupDocument = getPopupDocument();
   loPopupDocument.open();
   loPopupDocument.write(lsData);
   loPopupDocument.close();

   var loFields = loPopupDocument.getElementsByTagName("INPUT");
   for(var i=0; i<loFields.length; i++)
   {
      var loPopupField = loFields.item(i);
      var loDocumentField = loDataDocument.getElementById(loPopupField.name);
      if (loDocumentField)
      {
     	var lsValue = loDocumentField.value
      	if (loDocumentField.type == "checkbox")
      	{
      		if (!loDocumentField.checked) lsValue = null;
      	}
         if (lsValue != null) loPopupField.value = lsValue;
      }
   }
   var loPopupForm = loPopupDocument.PopupForm;
}

function getFormFields(foForm)
{
    var laField = new Array();
    addNodes(laField, foForm.getElementsByTagName("INPUT"));
    addNodes(laField, foForm.getElementsByTagName("TEXTAREA"));
    addNodes(laField, foForm.getElementsByTagName("SELECT"));
    return laField;
}

function addNodes(faField, foNodes)
{
    var loNode;
    for (var i=0; i<foNodes.length; i++)
    {
        loNode = foNodes.item(i);
        if (loNode.name != null && loNode.name.length > 0) faField.push(loNode);
    }
}

function setDate(fsFieldName, fsDate)
{
   loDocument = getDataDocument();
   loField = loDocument.getElementById(fsFieldName);
   loField.value = fsDate;
   hidePopup();
}

function setDateYMD(fsFieldName, fiYear, fiMonth, fiDay, fiShowTime)
{
	var maMonthNames = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
   loDocument = getDataDocument();
   var loField = loDocument.getElementById(fsFieldName);
   var lsDateFormat = top.DATE_FORMAT;
   var lsDate = lsDateFormat;
   var lsTime = "";
   if (fiShowTime == 1)
   {
        var loDate = new Date();
        lsTime = " " + loDate.getHours() + ":" + loDate.getMinutes() + ":" + loDate.getSeconds();
   }
   if (lsDateFormat == "dd/MM/yyyy")
   {
	   lsDate = fiDay + "/" + fiMonth + "/" + fiYear + lsTime;
	}
   else if (lsDateFormat == "MM/dd/yyyy")
   {
	   lsDate = fiMonth + "/" + fiDay + "/" + fiYear + lsTime;
	}
   else if (lsDateFormat == "dd-MMM-yyyy")
   {
	   lsDate = fiDay + "-" + maMonthNames[fiMonth - 1] + "-" + fiYear + lsTime;
	}

   loField.value = lsDate;
   hidePopup();
}

function submitPopup(foPopupForm)
{
   foPopupForm.setAttribute("action", top.SERVLET_ROOT + "Controller");
   foPopupForm.setAttribute("method", "post");
	foPopupForm.submit();
}

function showReport(fsReportURL)
{
    top.ReportFrame.location = fsReportURL;
    setFrameHeight(true, false);
}

function setFrameHeight(fbReportFrame, fbErrorFrame)
{
	lsHeaderFrameHeight = top.HeaderFrame.document.body.scrollHeight;
	lsDataFrameHeight = "*";
	lsReportFrameHeight = "0";
	lsMessageFrameHeight = "0";
	if (fbReportFrame)
	{
		lsDataFrameHeight = getDataDocument().body.scrollHeight;
		lsReportFrameHeight = "*";
	}
	if (fbErrorFrame) lsMessageFrameHeight = "22";
	if (fbErrorFrame && arguments.length > 2)
	{
	lsMessageFrameHeight = lsMessageFrameHeight * arguments[2];
	}
	top.document.body.rows = lsHeaderFrameHeight + ", " + lsDataFrameHeight + ", " + lsReportFrameHeight + ", " + lsMessageFrameHeight;
}

function showCalendar(fsFieldName)
{
	var lsMonth = 0;
	var lsYear = 0;
   if (arguments.length > 1) lsMonth = arguments[1];
   if (arguments.length > 2) lsYear = arguments[2];
   showPopup(fsFieldName, 188)
	paintCalendar(fsFieldName, lsMonth, lsYear, 0);
}

function showTimeCalendar(fsFieldName)
{
	var lsMonth = 0;
	var lsYear = 0;
   if (arguments.length > 1) lsMonth = arguments[1];
   if (arguments.length > 2) lsYear = arguments[2];
   showPopup(fsFieldName, 188)
	paintCalendar(fsFieldName, lsMonth, lsYear, 1);
}

function showCalculator()
{
	liLeft = screen.width - 150;

   loPopupFrame = getPopupFrame();
   loStyle = loPopupFrame.style;
   loStyle.left = liLeft;
   loStyle.top = 2;
   loStyle.width = 140;
   loStyle.height = 132;
   loStyle.display = "block";

	paintCalculator();
}

function showPopup(fsFieldName, fiWidth)
{
   loForm = getDataForm();
   loDocument = getDataDocument();
   loPopupFrame = getPopupFrame();
   loStyle = loPopupFrame.style;
   loField = loDocument.getElementById(fsFieldName);
   if (loField.type == "hidden")
   {
      loField = loDocument.getElementById(fsFieldName + "_refvalue");
   }
   liLeft = getOffsetLeft(loField);
   liWidth = loField.offsetWidth;
   if (liLeft > 675) liLeft = (liLeft + liWidth) - fiWidth;
   liTop = getOffsetTop(loField) + 20;
   loStyle.left = liLeft;
   loStyle.top = liTop;
   loStyle.width = fiWidth;
   liHeight = getPopupDocument().body.scrollHeight;
   if (liHeight < 18) liHeight = 18;
   loStyle.height = liHeight;
   loStyle.display = "block";
}

function hidePopup()
{
   loPopupFrame = getPopupFrame();
   if (loPopupFrame)
   {
      loPopupFrame.style.display = "none";
      loPopupFrame.style.height = "0";
      loPopupFrame.src = "javascript:''";
   }
}

function fitToSize(fsFieldName)
{
   loDocument = getDataDocument();
   loPopupFrame = getPopupFrame();
   loStyle = loPopupFrame.style;

   loField = loDocument.getElementById(fsFieldName);
   if (loField.type == "hidden")
   {
      loField = loDocument.getElementById(fsFieldName + "_refvalue");
   }
   liTop = getOffsetTop(loField) + 20;
   liBodyScroll = getBodyScroll(loField);

   liHeight = document.body.scrollHeight;
   if (liHeight > 325) liHeight = 325;

   liMaxTop = window.screen.availHeight - 173;
   if ((liHeight + liTop - liBodyScroll) > liMaxTop)
   {
      liTop = liTop - liHeight - 18;
   }
   if (liTop < 25) liTop = 25;
   loStyle.height = liHeight;
   loStyle.top = liTop;
}

function fitToException()
{
   loPopupFrame = getPopupFrame();
   loPopupFrame.style.width = 800;
   loPopupFrame.style.height = 500;
}

function displayMessage(fsMessage)
{
    lsImage = "feedback-error.gif";
    if (arguments.length > 1) lsImage = arguments[1];
    lsData = "<html>";
    lsData += "<head>";
    lsData += "<link href='" + top.INCLUDE + "/Stylesheet.css' type='text/css' rel='stylesheet'>";
    lsData+= "<script type='text/javascript' src='" + top.INCLUDE + "/Controller.js' language='JavaScript'></script>";
    lsData += "</head>";
    lsData += "<body class='message_body'>";
    lsData += "<table width=100% border=0 cellspacing=1 cellpadding=0>";
    lsData += "<tr>\r\n";
    lsImages =  new Array();
    lsImages = lsImage.split("|");
    lsData += "<td width=10><img src='" + top.IMAGES + "/" + lsImages[0] + "'>&nbsp;</td>\r\n";
    lsMessage = new Array();
    lsMessage = fsMessage.split("|");
    lsData += "<td><b>" + lsMessage[0] + "</b></td>\r\n";
    if (lsMessage.length > 1)
    {
    lsData += "<td width=25><a href='javascript:displayAllMessages(\"" + fsMessage + "\", \"" + lsImage  + "\");'> More </a></td>";
    }
    lsData += "</tr>\r\n";
    lsData += "</table>\r\n";
    lsData += "</body>";
    lsData += "</html>";
    loMessageDocument = top.MessageFrame.document;
    loMessageDocument.open();
    loMessageDocument.write(lsData);
    loMessageDocument.close();
    if (fsMessage == "")
        setFrameHeight(false, false);
    else
        setFrameHeight(false, true);
}

function displayAllMessages(fsMessage)
{
    lsImage = "feedback-error.gif";
    if (arguments.length > 1) lsImage = arguments[1];
    lsData = "<html>";
    lsData += "<head>";
    lsData += "<link href='" + top.INCLUDE + "/Stylesheet.css' type='text/css' rel='stylesheet'>";
    lsData+= "<script type='text/javascript' src='" + top.INCLUDE + "/Controller.js' language='JavaScript'></script>";
    lsData += "</head>";
    lsData += "<body class='message_body'>";
    lsData += "<table width=100% border=0 cellspacing=1 cellpadding=0>";
    lsImages =  new Array();
    lsImages = lsImage.split("|");
    lsMessage = new Array();
    lsMessage = fsMessage.split("|");
    for (var liCtr=0; liCtr<lsMessage.length; liCtr++)
    {
       lsData += "<tr>";
	    lsData += "<td width=10><img src='" + top.IMAGES + "/" + lsImages[liCtr] + "'>&nbsp;</td>";
    	 lsData += "<td><b>" + lsMessage[liCtr] + "</b></td>";
    	 if (liCtr+1 == lsMessage.length)
			    {
			    lsData += "<td width=25><a href='javascript:displayMessage(\"" + fsMessage + "\", \"" + lsImage  + "\");'>Less </a></td>";
			    }
    	 lsData += "</tr>";
    }

    lsData += "</table>\r\n";
    lsData += "</body>";
    lsData += "</html>";
    loMessageDocument = top.MessageFrame.document;
    loMessageDocument.open();
    loMessageDocument.write(lsData);
    loMessageDocument.close();
    if (fsMessage == "")
        setFrameHeight(false, false);
    else
        setFrameHeight(false, true, lsMessage.length);
}

function openNewWindow(fsURL)
{
	lsParams = "toolbar=no, location=no, directories=no, status=no, menubar=no, copyhistory=no";
	lsParams += ", resizable=yes, left=0, top=0";
	loWindow = window.open(fsURL, 'ReportWindow', lsParams)
	//loWindow.moveTo(0,0);
	loWindow.resizeTo(screen.width, screen.height - 25);
}

function setSubSystem(fsSessionId, fiSubSystem, fbResetDesktop)
{
	top.HeaderFrame.location = top.SERVLET_ROOT + "Header?session_id=" + fsSessionId + "&sub_system=" + fiSubSystem;
	if (fbResetDesktop)
	{
		processRequest(ACTN_RESET_DESKTOP);
	}
}

function showTabSection(fiTabSection)
{
   liCtr = 0;
   while(true)
   {
      loSection = document.getElementById("TabSection" + liCtr);
      if (!loSection) break;

		if (fiTabSection == liCtr)
		{
			loSection.style.display = "block" ;
		}
		else
		{
			loSection.style.display = "none";
		}
      liCtr++;
   }
}

function expandAllSections()
{
   liCtr = 1;
   while(true)
   {
      loSection = document.getElementById("ExpandingSection" + liCtr);
      if (loSection)
      {
         expandSection(loSection);
         liCtr++;
      }
      else
      {
         break;
      }
   }
}

function collapseAllSections()
{
   liCtr = 1;
   while(true)
   {
      loSection = document.getElementById("ExpandingSection" + liCtr);
      if (loSection)
      {
         collapseSection(loSection);
         liCtr++;
      }
      else
      {
         break;
      }
   }
}

function expandSection(foSection)
{
   foSection.style.display = "block" ;
   loImage = document.getElementById(loSection.id + "Image");
   loImage.src = top.IMAGES + "/expandSection.gif";
}
function collapseSection(foSection)
{
   foSection.style.display = "none";
   loImage = document.getElementById(loSection.id + "Image");
   loImage.src = top.IMAGES + "/collapseSection.gif";
}

function toggleSection(fsSection)
{
   loSection = document.getElementById(fsSection);
   if(loSection.style.display == "block")
   {
      collapseSection(loSection);
   }
   else
   {
      expandSection(loSection);
   }
}

function setFocusField(fsFieldName)
{
   loField = document.getElementById(fsFieldName);
	if (loField) loField.focus();
}

function setFocusFirstButton()
{
   loButtons = document.getElementsByTagName("button");
   for (liCtr=0; liCtr<loButtons.length; liCtr++)
   {
      loButton = loButtons.item(liCtr);
      if (!loButton.disabled)
      {
         loButton.focus();
         break;
      }
   }
}

function getOffsetLeft(foElement)
{
   liOffset = foElement.offsetLeft;
   while ((foElement = foElement.offsetParent) != null)
   {
      liOffset += foElement.offsetLeft;
   }
   return liOffset;
}

function getOffsetTop(foElement)
{
   liOffset = foElement.offsetTop;
   while((foElement = foElement.offsetParent) != null)
   {
      liOffset += foElement.offsetTop;
   }
   return liOffset;
}

function getBodyScroll(foElement)
{
   while((foElement = foElement.offsetParent) != null)
   {
   	if (foElement.tagName == "BODY")
   	{
	   	return foElement.scrollTop;
   	}
   }
}

function paintCalendar(fsFieldName, fiMonth, fiYear, fiShowTime)
{
	var maMonthNames = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
	var maDaysInMonth = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

	var lsData = "";

	lsData += "<html>\r\n";
	lsData += "<head>\r\n";
   lsData += "<link href='" + top.INCLUDE + "/Stylesheet.css' type='text/css' rel='stylesheet'>";
   lsData += "<script type='text/javascript' src='" + top.INCLUDE + "/Controller.js' language='JavaScript'></script>\r\n";
	lsData += "</head>\r\n";
	lsData += "<body style='margin:0px;' onLoad=\"fitToSize('" + fsFieldName + "');\">\r\n";
	lsData += "<table class='popupcal' width=100% border=0 cellspacing=0 cellpadding=2>\r\n";

	var loCalendar = new Date();
	if (fiMonth == 0) fiMonth = loCalendar.getMonth() + 1;
	if (fiYear == 0) fiYear = loCalendar.getFullYear();

	if ((fiYear % 4 == 0 && fiYear % 100 != 0) || fiYear % 400 == 0)
	{
		maDaysInMonth[1] = 29;
	}
	else
	{
		maDaysInMonth[1] = 28;
	}

	var liDisplayYear = fiYear;
	var liDisplayMonth = fiMonth;
	var liDisplayDate = 1;

	loCalendar = new Date(fiYear, fiMonth - 1, 1);

	var liWeekDay = loCalendar.getDay();
	if (liWeekDay > 0)
	{
		liDisplayMonth--;
		if (liDisplayMonth < 1)
		{
			liDisplayMonth = 12;
			liDisplayYear--;
		}
		liDisplayDate = maDaysInMonth[liDisplayMonth - 1] - liWeekDay + 1;
	}

	var liNextMonth = fiMonth + 1;
	var liNextMonthYear = fiYear;
	if (liNextMonth > 12)
	{
		liNextMonth = 1;
		liNextMonthYear++;
	}

	var liPreviousMonth = fiMonth - 1;
	var liPreviousMonthYear = fiYear;
	if (liPreviousMonth < 1)
	{
		liPreviousMonth = 12;
		liPreviousMonthYear--;
	}

	var liNextYear = fiYear + 1;
	var liPreviousYear = fiYear - 1;

	lsData += "<tr class='main_hdr'>\r\n";
	if(fiShowTime == 1)
	{
	    lsData += "<td><a title='Previous Year' href='javascript:parent.showTimeCalendar(\"" + fsFieldName + "\"," + fiMonth + "," + liPreviousYear + ")'>\r\n";
    	lsData += "<img src='" + top.IMAGES + "/end-left.gif'></a></td>\r\n";
    	lsData += "<td><a title='Previous Month' href='javascript:parent.showTimeCalendar(\"" + fsFieldName + "\"," + liPreviousMonth + "," + liPreviousMonthYear + ")'>\r\n";
    	lsData += "<img src='" + top.IMAGES + "/left.gif'></a></td>\r\n";
    	lsData += "<td colspan=3>" + maMonthNames[fiMonth - 1] + " " + fiYear + "</td>\r\n";
    	lsData += "<td><a title='Next Month' href='javascript:parent.showTimeCalendar(\"" + fsFieldName + "\"," + liNextMonth + "," + liNextMonthYear + ")'>\r\n";
    	lsData += "<img src='" + top.IMAGES + "/right.gif'></a></td>\r\n";
    	lsData += "<td><a title='Next Year' href='javascript:parent.showTimeCalendar(\"" + fsFieldName + "\"," + fiMonth + "," + liNextYear + ")'>\r\n";
    	lsData += "<img src='" + top.IMAGES + "/end-right.gif'</a></td>\r\n";
	}
	else
	{
        lsData += "<td><a title='Previous Year' href='javascript:parent.showCalendar(\"" + fsFieldName + "\"," + fiMonth + "," + liPreviousYear + ")'>\r\n";
        lsData += "<img src='" + top.IMAGES + "/end-left.gif'></a></td>\r\n";
        lsData += "<td><a title='Previous Month' href='javascript:parent.showCalendar(\"" + fsFieldName + "\"," + liPreviousMonth + "," + liPreviousMonthYear + ")'>\r\n";
        lsData += "<img src='" + top.IMAGES + "/left.gif'></a></td>\r\n";
        lsData += "<td colspan=3>" + maMonthNames[fiMonth - 1] + " " + fiYear + "</td>\r\n";
        lsData += "<td><a title='Next Month' href='javascript:parent.showCalendar(\"" + fsFieldName + "\"," + liNextMonth + "," + liNextMonthYear + ")'>\r\n";
        lsData += "<img src='" + top.IMAGES + "/right.gif'></a></td>\r\n";
        lsData += "<td><a title='Next Year' href='javascript:parent.showCalendar(\"" + fsFieldName + "\"," + fiMonth + "," + liNextYear + ")'>\r\n";
        lsData += "<img src='" + top.IMAGES + "/end-right.gif'</a></td>\r\n";
	}
	lsData += "</tr>\r\n";
	lsData += "<tr class='day_hdr'>\r\n";
	lsData += "<td width=12%>S</td>\r\n";
	lsData += "<td width=14%>M</td>\r\n";
	lsData += "<td width=14%>T</td>\r\n";
	lsData += "<td width=14%>W</td>\r\n";
	lsData += "<td width=14%>T</td>\r\n";
	lsData += "<td width=14%>F</td>\r\n";
	lsData += "<td width=14%>S</td>\r\n";
	lsData += "</tr>\r\n";

	var lsClass;
	loCalendar = new Date();
	var loCurrentDay = new Date();
	for (var liRow = 0; liRow < 6; liRow++)
	{
		lsData += "<tr>\r\n";
		for (var liCol = 0; liCol < 7; liCol++)
		{
			if (liDisplayMonth == loCalendar.getMonth() + 1 && liDisplayDate == loCalendar.getDate() && liDisplayYear == loCalendar.getFullYear())
			{
				lsClass = "day_today";
			}
			else if (liDisplayMonth == fiMonth)
			{
				lsClass = null;
			}
			else
			{
				lsClass = "month_other";
			}

			lsData += "<td";
			if (lsClass != null)
			{
				lsData += " class='" + lsClass + "'";
			}
			lsData += ">";

			loCurrentDay = new Date(liDisplayYear, liDisplayMonth - 1, liDisplayDate);
			var lsDate = loCurrentDay;
			lsData += "<a href=\"javascript:parent.setDateYMD('" + fsFieldName + "'," + liDisplayYear + "," + liDisplayMonth + "," + liDisplayDate + "," + fiShowTime + ");\">" + liDisplayDate + "</a></td>\r\n";
			liDisplayDate++;
			if (liDisplayDate > maDaysInMonth[liDisplayMonth - 1])
			{
				liDisplayDate = 1;
				liDisplayMonth++;
			}
			if (liDisplayMonth > 12)
			{
				liDisplayMonth = 1;
				liDisplayYear++;
			}
		}
		lsData += "</tr>\r\n";
		if (liDisplayMonth != fiMonth) break;
	}

	lsData += "</table></body></html>";

   loPopupDocument = getPopupDocument();
   loPopupDocument.open();
   loPopupDocument.write(lsData);
   loPopupDocument.close();
}

function paintCalculator()
{
	var lsData = "";

	lsData += "<html>\r\n";
	lsData += "<head>\r\n";
	lsData += "<title>Calculator</title>\r\n";
	lsData += "<link href='" + top.INCLUDE + "/Stylesheet.css' type='text/css' rel='stylesheet'>\r\n";
	lsData += "<script type='text/javascript' src='" + top.INCLUDE + "/Calculator.js' language='JavaScript'></script>\r\n";
	lsData += "</head>\r\n";
	lsData += "<body onload='javascript:moCalculator.SetFocus();' onkeyup='javascript:eventHandler(event);'>\r\n";
	lsData += "<table class='popupcalc' border=0 cellspacing=1 cellpadding=0>\r\n";
	lsData += "<tr>\r\n";
	lsData += "<td class='calc_result' colspan=5><input class='calc_result_input' type='text' id='display' name='display' readonly='true' value='0'></td>\r\n";
	lsData += "</tr>\r\n";
	lsData += "<tr>\r\n";
	lsData += "<td class='calc_button'><a href=\"javascript:moCalculator.EnterNumber('7');\">&nbsp;7&nbsp;</a></td>\r\n";
	lsData += "<td class='calc_button'><a href=\"javascript:moCalculator.EnterNumber('8');\">&nbsp;8&nbsp;</a></td>\r\n";
	lsData += "<td class='calc_button'><a href=\"javascript:moCalculator.EnterNumber('9');\">&nbsp;9&nbsp;</a></td>\r\n";
	lsData += "<td class='calc_button'><a href=\"javascript:moCalculator.OnOperator(247);\">&nbsp;&#247;&nbsp;</a></td>\r\n";
	lsData += "<td class='calc_button'><a href=\"javascript:moCalculator.OnClear();\">&nbsp;C&nbsp;</a></td>\r\n";
	lsData += "</tr>\r\n";
	lsData += "<tr>\r\n";
	lsData += "<td class='calc_button'><a href=\"javascript:moCalculator.EnterNumber('4');\">&nbsp;4&nbsp;</a></td>\r\n";
	lsData += "<td class='calc_button'><a href=\"javascript:moCalculator.EnterNumber('5');\">&nbsp;5&nbsp;</a></td>\r\n";
	lsData += "<td class='calc_button'><a href=\"javascript:moCalculator.EnterNumber('6');\">&nbsp;6&nbsp;</a></td>\r\n";
	lsData += "<td class='calc_button'><a href=\"javascript:moCalculator.OnOperator(215);\">&nbsp;&#215;&nbsp;</a></td>\r\n";
	lsData += "<td class='calc_button'>&nbsp;</td>\r\n";
	lsData += "</tr>\r\n";
	lsData += "<tr>\r\n";
	lsData += "<td class='calc_button'><a href=\"javascript:moCalculator.EnterNumber('1');\">&nbsp;1&nbsp;</a></td>\r\n";
	lsData += "<td class='calc_button'><a href=\"javascript:moCalculator.EnterNumber('2');\">&nbsp;2&nbsp;</a></td>\r\n";
	lsData += "<td class='calc_button'><a href=\"javascript:moCalculator.EnterNumber('3');\">&nbsp;3&nbsp;</a></td>\r\n";
	lsData += "<td class='calc_button'><a href=\"javascript:moCalculator.OnOperator(45);\">&nbsp;&#45;&nbsp;</a></td>\r\n";
	lsData += "<td class='calc_button'>&nbsp;</td>\r\n";
	lsData += "</tr>\r\n";
	lsData += "<tr>\r\n";
	lsData += "<td class='calc_button'><a href=\"javascript:moCalculator.EnterNumber('0');\">&nbsp;0&nbsp;</a></td>\r\n";
	lsData += "<td class='calc_button'>&nbsp;</td>\r\n";
	lsData += "<td class='calc_button'><a href=\"javascript:moCalculator.EnterNumber('.');\">&nbsp;.&nbsp;</a></td>\r\n";
	lsData += "<td class='calc_button'><a href=\"javascript:moCalculator.OnOperator(43);\">&nbsp;&#43;&nbsp;</a></td>\r\n";
	lsData += "<td class='calc_button'><a href=\"javascript:moCalculator.OnEqual();\">&nbsp;=&nbsp;</a></td>\r\n";
	lsData += "</tr>\r\n";
	lsData += "</table>\r\n";
	lsData += "</body>\r\n";
	lsData += "</html>\r\n";

   loPopupDocument = getPopupDocument();
   loPopupDocument.open();
   loPopupDocument.write(lsData);
   loPopupDocument.close();
}
